#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstdint>
#include <ctime>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode* head;
public:
    ListNode* reverseList(ListNode* head) {
        ListNode *head_pre = NULL;
        while(head){
            ListNode *temp = head->next;
            head->next = head_pre;
            head_pre = head;
            head = temp;
        }
        return head_pre;
    }
};

ListNode* createList(int num, uint32_t max)
{
    ListNode* head;
    ListNode* node;
    if (0 == num) return NULL;
    srand(clock());
    head = new ListNode(rand()%max);
    node = head;
    for (int i = 0; i < num-1; i++){
        node->next = new ListNode(rand()%max);
        node = node->next;
    }
    return head;
}

void printList(ListNode* node)
{
    int cnt = 0;
    cout << "node print start:" << endl;
    while(node){
        cout << ++cnt << ":" << node->val << endl;
        node = node->next;
    }
    cout << "node print end" << endl;
}

int main(void)
{
    Solution su;
    su.head = createList(30, 100);
    printList(su.head);
    ListNode* list = su.reverseList(su.head);
    printList(list);
    return 0;
}
